/*
 * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package top.continew.admin.hanfu.controller;

import lombok.RequiredArgsConstructor;
import net.dreamlu.mica.core.result.R;
import org.springframework.web.bind.annotation.*;

import top.continew.admin.hanfu.domain.ActiveTable;
import top.continew.admin.hanfu.domain.dto.ActiveTableDto;
import top.continew.admin.hanfu.service.impl.ActiveTableServiceImpl;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author bbm
 * @since 2025-03-31
 */
@RestController
@RequestMapping("/active_table")
@RequiredArgsConstructor
public class ActiveTableController {

    private final ActiveTableServiceImpl activeTableService;

    /**
     * 获取表id
     * 
     * @param id 活动id
     */
    @GetMapping("/active/{id}")
    public R getActiveTableIdByActveId(@PathVariable("id") Integer id) {
        ActiveTable one = activeTableService.lambdaQuery().eq(ActiveTable::getActiveId, id).one();

        if (one == null) {
            return R.success(0);
        }

        return R.success(one.getId());
    }

    /**
     * 新增活动表
     * 
     * @param activeTableDto 活动表dto
     */
    @PostMapping("")
    public R<String> addActiveTable(@RequestBody ActiveTableDto activeTableDto) {

        ActiveTable activeTable = new ActiveTable();
        activeTable.setTableName(activeTableDto.getTableName());
        activeTable.setStatus(1 + "");
        activeTable.setActiveId(activeTableDto.getActiveId());
        activeTable.setUpdateBy(activeTableDto.getUpdateBy());
        activeTable.setUpdateTime(System.currentTimeMillis() + "");
        activeTableService.save(activeTable);

        return R.success(activeTable.getId() + "");
    }

}
